package com.alibaba.controller;

import com.alibaba.config.AopAdvice;
import com.alibaba.entity.Config;
import com.alibaba.entity.Person;
import com.alibaba.entity.User;
import com.alibaba.entity.ZhiWenBean;
import com.alibaba.service.UserAop;
import com.alibaba.service.impl.UserImpl;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;


/**
 * @Author: zhuangzhiwen
 * @Date: 2021/8/17
 */

/**
 * spring  bean 几种创建方式
 */
public class BeanTest {
    public static void main(String[] args) {
//        ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");
//        User user = context.getBean("user", User.class);
//        System.out.println(user);


//        AnnotationConfigApplicationContext context=new AnnotationConfigApplicationContext(User.class);
//        System.out.println(context);

//        AnnotationConfigApplicationContext context=new AnnotationConfigApplicationContext(Config.class);
//        System.out.println(context);

//        AnnotationConfigApplicationContext context=new AnnotationConfigApplicationContext();
//        context.refresh();
//        User user = context.getBean("user", User.class);
//        System.out.println(user);

//        AnnotationConfigApplicationContext context=new AnnotationConfigApplicationContext();
//        AbstractBeanDefinition beanDefinition = BeanDefinitionBuilder.genericBeanDefinition().getBeanDefinition();
//        beanDefinition.setBeanClass(User.class);
//        context.registerBeanDefinition("user",beanDefinition);
//        context.refresh();
//        User user = context.getBean("user", User.class);
//        System.out.println(user.getName());

//        AnnotationConfigApplicationContext context=new AnnotationConfigApplicationContext();
//        context.registerBean(User.class, new Supplier<User>() {
//            public User get() {
//                User user = new User();
//                user.setName("cccc");
//                return user;
//            }
//        });
//        context.refresh();
//        User user = context.getBean("user", User.class);
//        System.out.println(user.getName());


//        ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");
//        UserAop userImpl = context.getBean("userImpl", UserAop.class);
//        userImpl.add();
//        AnnotationConfigApplicationContext context=new AnnotationConfigApplicationContext(Config.class);
//        User user = context.getBean("user", User.class);

    }
}
